package com.zilu.digitaltwin.controller;

import com.zilu.digitaltwin.common.util.InitSqlUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api")
public class SqlInitController {


    @PostMapping("/sql/init")
    public void createSql(@RequestParam String codes, @RequestParam String dataVersion) throws Exception {
        if ("FETCH_ALL".equals(codes)) {
            codes = InitSqlUtil.getInitCodes(dataVersion);
        }
        if (StringUtils.isBlank(codes)) {
            throw new RuntimeException("dataVersion = " + dataVersion + " 下无维护的实体");
        }
        InitSqlUtil.initSql(codes, dataVersion);
    }

    @GetMapping("/sql/getInitCodes")
    public String createSql(@RequestParam String dataVersion) {
        return InitSqlUtil.getInitCodes(dataVersion);
    }
}
